package cn.edu.jxau.test;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;

/**
 * @author Fudashi
 */
public class Main {

	public static void main(String[] args) {

		System.out.println(foo(new String[] { "3", "32", "321" }));
	}

	public static String foo(String[] strArr) {

		// 1.参数校验 //
		Objects.requireNonNull(strArr, "参数strArr为null");
		if (strArr.length == 0) {
			throw new IllegalArgumentException("参数strArr是一个空数组");
		}

		// 2.排序 //
		Arrays.sort(strArr, new Comparator<String>() {
			@Override
			public int compare(String s1, String s2) {
				String a = s1 + s2;
				String b = s2 + s1;
				return a.compareTo(b);
			}
		});

		// 3.拼接字符串 //
		StringBuilder result = new StringBuilder();
		for (int i = 0; i < strArr.length; i++) {
			result.append(strArr[i]);
		}
		return result.toString();
	}
}
